package com.wowudi.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wowudi.dto.ListDto;
import com.wowudi.entity.OperationType;
import com.wowudi.service.DepartmentClassService;
import com.wowudi.service.OperationTypeService;
import com.wowudi.util.MsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/fina/optype")
public class OpTypeController {

        @Autowired
        private OperationTypeService operationTypeService;
        @Autowired
        private DepartmentClassService departmentClassService;
        @RequestMapping("findOptype")
        public Page<OperationType> findPati(Integer pageym , Integer pagesize, String cartid, String patiname) {
            Page<OperationType> page = new Page<OperationType>(pageym,pagesize);
            //this.operationTypeService.page(page)
            this.operationTypeService.getAllBynameandid(page,cartid,patiname);
            return page;
        }
    //添加
        @RequestMapping("addOptype")
        public MsgUtil addPati(@RequestBody OperationType operationType) {
                operationType.setHoyIsdel(0);
            Boolean bool=this.operationTypeService.save(operationType);
            // Integer bool=this.doctorAdviceService.addDoct(doctorAdvice,list);
            if (bool){
                return new MsgUtil(true,"添加成功",null);
            }else {
                return new MsgUtil(false,"添加失败",null);
            }
        }

        //删除
        @RequestMapping("delOptype")
        public MsgUtil delPati(Integer id) {
            OperationType operationType=this.operationTypeService.getById(id);
            operationType.setHoyIsdel(1);
            boolean bool=this.operationTypeService.updateById(operationType);
            if (bool){
                return new MsgUtil(true,"删除成功",null);
            }else {
                return new MsgUtil(false, "删除失败", null);
            }
        }
        @RequestMapping("getListDto")
        public ListDto getListDto() {
            ListDto listDto=new ListDto();
            listDto.setDepartmentClassList(this.departmentClassService.list());
            return listDto;
        }
    //修改
    @RequestMapping("upOptype")
    public MsgUtil upOptype(@RequestBody OperationType operationType) {
        Boolean bool=this.operationTypeService.updateById(operationType);
        // Integer bool=this.doctorAdviceService.addDoct(doctorAdvice,list);
        if (bool){
            return new MsgUtil(true,"修改成功",null);
        }else {
            return new MsgUtil(false,"修改失败",null);
        }
    }
    //显示修改ui
    @RequestMapping("upOptypeui")
    public OperationType upPatiui(Integer id) {
        OperationType hoPay=this.operationTypeService.getById(id);
        return hoPay;
    }
}
